package com.pi.shisan.service.schedule.job.support;

import com.pi.shisan.service.audio.AudioEffectComponentsSupplier;
import com.pi.shisan.service.audio.AudioPlayer;
import com.pi.shisan.service.util.ComponentManager;

/**
 * 空播放器，目的是为了让不放音乐的组件可以展示
 * 因为目前封装的是LED和播放器强绑定
 */
public class EmptyPlayer extends AudioPlayer {

    public EmptyPlayer(AudioEffectComponentsSupplier<ComponentManager.MusicEffectBaseComponent> musicEffectComponentsSupplier) throws Exception {
        super(null, musicEffectComponentsSupplier);
    }

    @Override
    protected boolean doingPlay() throws Exception {
        synchronized (playerStatus) {
            while (playerStatus.get() == PLAYING) {
                try {
                    playerStatus.wait();
                } catch (InterruptedException e) {
                }
            }
        }
        return playerStatus.get() == DESTROYED;
    }

    @Override
    protected void reset() throws Exception {

    }

    @Override
    public void interrupt() {
        super.interrupt();
        synchronized (playerStatus) {
            playerStatus.notifyAll();
        }
    }

    @Override
    public void destroy() {
        playerStatus.set(DESTROYED);
        synchronized (playerStatus) {
            playerStatus.notifyAll();
        }
    }

    @Override
    protected void doDestroy() {

    }
}